#include<iostream>
#include<unistd.h>
#include<vector>
#include<functional>
#include<stdlib.h>
#include<signal.h>
#include<string>
using namespace std;

typedef function<void()> func;
vector<func> callback;
int count = 0;
void handler(int sigid)
{
    cout << "我的pid是:" << getpid()  << " 给我发的信号是:" << sigid << endl;
    alarm(1);
}

void showCount()
{
    cout << "我的pid是:" << getpid()  << " 给我发的信号是:" << endl;
    cout << count << endl;
}

void showLog()
{
    cout << "这个是日志" << endl;
}

void catchSig(int sigid)//定时器功能
{
    for(auto f: callback)
    {
        f();
    }
    alarm(1);//触发以后调用时再设置一个定时器
}

static void usage(string proc)
{
    cout << "usage:\r\n\t" << proc << "signalnumber processid" << endl;
}
int main(int argc, char* argv[])
{
    //signal(SIGINT,handler);
    // signal(SIGALRM,catchSig);//实现一个定时器功能
    // alarm(1);
    // callback.push_back(showCount);//函数指针数组
    // callback.push_back(showLog);
    //abort(); //给自己发送终止进程的信号

    //实现一个类似kill的程序
    if(argc != 3)
    {
        usage(argv[0]);
        exit(1);
    }
    int signumber = stoi(argv[1]);
    int processid = stoi(argv[2]);
    kill(processid,signumber);
    return 0;
}